var uiPanel = require("uiPanel"); //初始化uiPanel参数
cc.Class({
    extends: uiPanel,  //继承uiPanel类
    properties: {},

    onLoad() {
        this._super();
    },

    start() {
        //uiPanl里重写的时间监听方法,第一个是监听事件类型，第二个是回调函数（即监听成功之后执行的方法），第三个是回调的目标。
        this.nodeDict["start"].on("click", Game.GameManager.matchVsInit, Game.GameManager);
        //判断是否微信端登陆，true就创建一个微信按钮
        if (window.wx) {
            wx.getUserInfo({
                    success: function(res) {
                        console.log("wx.getUserInfo success");
                        Game.GameManager.nickName = res.userInfo.nickName;
                        Game.GameManager.avatarUrl = res.userInfo.avatarUrl;
                    }.bind(this),
                    fail: function() {
                        console.log("wx.getUserInfo fail");
                        //节点里的key_start节点隐藏
                        this.nodeDict["start"].active = false;
                        //按钮信息
                        wx.getSystemInfo({
                            success: function(data) {
                                Game.GameManager.getUserInfoBtn = wx.createUserInfoButton({
                                    type: 'text',
                                    text: '开始多人游戏',
                                    style: {
                                        left: data.screenWidth * 0.2,
                                        top: data.screenHeight * 0.73,
                                        width: data.screenWidth * 0.65,
                                        height: data.screenHeight * 0.07,
                                        lineHeight: data.screenHeight * 0.07,
                                        backgroundColor: '#fe714a',
                                        color: '#ffffff',
                                        textAlign: 'center',
                                        fontSize: data.screenHeight * 0.025,
                                        borderRadius: 8
                                    }
                                });
                                Game.GameManager.getUserInfoBtn.onTap(function(res) {
                                    console.log(res);
                                    if (Game.GameManager.isClickCd) {
                                        return;
                                    }
                                    Game.GameManager.isClickCd = true;
                                    setTimeout(function() {
                                        Game.GameManager.isClickCd = false;
                                    }, 1000);
                                    //微信账号信息
                                    if(res.userInfo) {
                                        Game.GameManager.nickName = res.userInfo.nickName;
                                        Game.GameManager.avatarUrl = res.userInfo.avatarUrl;
                                        Game.GameManager.matchVsInit();
                                        Game.GameManager.getUserInfoBtn.hide();
                                    }
                                });
                            }
                        })
                    }.bind(this),
                }
            );
        }
    },


    //按钮隐藏与显示
    onEnable() {
        if (Game.GameManager.getUserInfoBtn) {
            Game.GameManager.getUserInfoBtn.show();
        }
    }
    ,

    onDisable() {
        if (Game.GameManager.getUserInfoBtn) {
            Game.GameManager.getUserInfoBtn.hide();
        }
    }
})
;
